package com.zte.stats.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.stats.dao.IStatsStockDao;
import com.zte.stats.model.StatsRkWarehouse;
import com.zte.stats.model.StatsDeliveryCondition;
import com.zte.stats.model.StatsRkWarehouse;
import com.zte.stats.model.StatsWarehouse;
import com.zte.stats.service.IStatsStockService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service

public class StatsStockServiceImpl implements IStatsStockService {

    @Autowired
    private IStatsStockDao iStatsStockDao;

    @Override
    public PageModel<StatsWarehouse<StatsRkWarehouse>> queryWarehouseList(PageModel<StatsWarehouse<StatsRkWarehouse>> pageModel, StatsDeliveryCondition sdc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsWarehouse<StatsRkWarehouse>> statsWarehouses = iStatsStockDao.queryWarehouse(sdc);
        PageInfo<StatsWarehouse<StatsRkWarehouse>> info = new PageInfo<StatsWarehouse<StatsRkWarehouse>>(statsWarehouses);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsWarehouse<StatsRkWarehouse>>(info.getList()));
        return pageModel;
    }

    @Override
    public PageModel<StatsRkWarehouse> queryRKWarehouseList(PageModel<StatsRkWarehouse> pageModel, StatsDeliveryCondition sdc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsRkWarehouse> statsRkWarehouses = iStatsStockDao.queryRKWarehouse(sdc);
        PageInfo<StatsRkWarehouse> info = new PageInfo<StatsRkWarehouse>(statsRkWarehouses);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsRkWarehouse>(info.getList()));
        return pageModel;
    }
}
